package com.lsu.app.mapper;

import com.lsu.app.bean.Resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 *
 * @description 针对表【resource(图片/视频文件)】的数据库操作Mapper
 * @Date 2023-10-20 18:13:30
 * @author hjj
 */
@Mapper
public interface ResourceMapper extends BaseMapper<Resource> {
    @Select("select * from resource where uorr_id = (select id from user where username = #{username})")
    Resource getResourceByUsername(String username);
    @Select("select url from resource where uorr_id = #{id} and type = 2")
    String getHeadUrlByUorrIdAndType(@Param("id") Integer id);//获取头像url
    @Select("select url from resource where id = #{id}")
    String getVideoUrlByUorrIdAndId(@Param("id") Integer id);//获取视频url

    @Select("select id from resource where type = 1  and uorr_id  = #{courseId}")
    List<Integer> getIdsByCourseId(Integer courseId);//获取视频资源id集合
    @Select("select uorr_id from  resource where id=#{id}")
    Integer getUorrIdById(Integer id);//根据视频id获取uorr_id

    @Select("select course_progress from course where id=#{id}")
    Integer getEpisodesByUorrId(Integer id);//获取课程集数
    @Select("select url from resource where type=3 and uorr_id = #{id}")
    String getCoverImgUrlByCourseId(Integer id);//获取封面图片url
    @Update("update resource set episodes = episodes-1 where episodes > #{episodes}")
    void adjustEpisodes(Integer episodes);//调整集数
    @Select("select url from resource where type=4 and uorr_id = #{talkId}")
    List<String> getTalkImgsUrlByTalkId(Integer talkId);//获取话题图片集合
    @Select("select `name` from user where id = (select teacher_id from course where id = #{uorrId})")
    String getTeacherNameByVideoId(Integer uorrId);
    @Select("select COUNT(*) from resource where type=1 and remake = #{remake} and uorr_id=#{courseId}")
    Integer getCountOfRemake(@Param("remake") String remake,@Param("courseId") Integer courseId);//查询相同的视频名称

    @Select("select url from resource where type=3 and uorr_id=#{courseId}")
    String getCourseCoverUrlByVideoId(Integer CourseId);//通过课程视频id，获取到课程封面
    @Select("select teacher_id from course where id = (select uorr_id from resource where id=#{id})")
    Integer getTeacherIdByVideoId(Integer id);//根据课程视频id获取课程id
    @Select("select teacher_id from course where id=#{courseId}")
    Integer getTeacherIdByCourseId(Integer courseId);//根据课程id获取教师id
    @Select("select course_name from course where id = (select uorr_id from resource where id=#{id})")
    String getCourseNameByVideoId(Integer id);//根据视频id获取课程名称
    @Select("select id from resource where type=#{type} and uorr_id=#{id}")
    List<Integer> getReIdsByTypeAndUorrId(@Param("type") Integer type,@Param("id") Integer id);
}




